import React, { useEffect, useState } from "react";
import { Row, Col } from 'antd';

import List from "../components/classify/List";
import Update from "../components/classify/Update";
import Add from "../components/classify/Add";
import Search from "../components/classify/SearchElement";
import { getAll } from "../services/classify";
export default function Classify() {
    let [classify, setClassify] = useState([]);
    let [pagination, setPagination] = useState({
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: (total) => `总共 ${total} 条`,
        pageSizeOptions: [5, 10, 15, 20],
    });
    let [searchObj, setSearchObj] = useState({});
    const show = async (params) => {
        if (params) {
            if (!params.current) {
                params.current = 1;
                params.pageSize = pagination.pageSize;
            }
            params = { ...searchObj, ...params }
            setSearchObj(params);
        } else {
            params = searchObj;
        }
        let data = await getAll(params);
        console.log(data);
        setClassify(data.data.rows);
        setPagination({
            ...pagination,
            total: data.data.total,
            current: parseInt(data.data.current),
            pageSize: data.data.pageSize,
        })
    };
    useEffect(() => {
        show();
    }, [classify.length]);
    return (
        <>
            <Row>
                <Col span={1}>
                    <Add show={show} ></Add>
                </Col>
                <Col span={12} offset={1}>
                    <Search show={show} ></Search>
                </Col>
            </Row>
            <Update
                show={show}

            ></Update>
            <List
                show={show}
                classify={classify}
                pagination={pagination}

            >
            </List>
        </>
    );
}



